package com.atguigu.gulimall.order.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
 * 自定义线程池
 */
@Configuration
public class MyThreadConfig {
    @Bean
    public ThreadPoolExecutor threadPoolExecutor(ThreadPoolConfigProperties pool){
        return new ThreadPoolExecutor(pool.getCore(),    //核心线程数 20
                pool.getMaxSize(),    //最大线程数 200
                pool.getKeepAliveTime(),    //存活时间 10
                TimeUnit.SECONDS,    //时间单位：秒
                new LinkedBlockingQueue<>(100000),    //阻塞队列
                Executors.defaultThreadFactory(),    //默认线程工厂
                new ThreadPoolExecutor.AbortPolicy());    //拒绝策略
    }}
